begintownscript;

variables;
short choice,on,off;
string teststring;

body;

beginstate INIT_STATE;
	add_range_to_group(12,15,1);
	add_range_to_group(19,22,2);
	set_mobility(11,0);
	set_mobility(1001,0);
	set_name(12,"Stoic Ogre");
	set_name(13,"Pensive Ogre");
	set_name(14,"Ticklish Ogre");
	set_name(15,"Big Ogre");
	set_level(1002,8);
	on = 1;
	off = 0;
break;

beginstate START_STATE;
	if(get_flag(2,15) <= 0){
		message_dialog("You enter the cave full of monsters The Boss wants exterminated.  It's time to kill them dead.","");
		set_flag(2,15,1);
		}

	if((get_flag(2,2) == 1) && (get_flag(10,20) <= 8)){
		if((char_on_loc(15,21) == -1) && (char_on_loc(16,21) == 11)){
			relocate_character(11,15,21);
			force_instant_terrain_redraw();
			}
		if((char_on_loc(14,21) == -1) && (char_on_loc(15,21) == 11)){
			relocate_character(11,14,21);
			force_instant_terrain_redraw();
			}
		if((char_on_loc(13,21) == -1) && (char_on_loc(14,21) == 11)){
			relocate_character(11,13,21);
			force_instant_terrain_redraw();
			}
		inc_flag(10,20,1);
		}

	if(char_on_loc(13,21) == 11){
		message_dialog("With a clearer path to the exit, Nelson shoves you aside and bounds forward and leaves, shouting 'hallelueahs' along the way.","");
		erase_char(11);
		set_flag(2,2,2);
		}

	if(get_flag(10,20) >= 6){
		reset_dialog();
		add_dialog_str(0,"Enough is enough, Nelson has blocked your way for too long!  Look at him just trying to push his way past you, like he's better than you!  It's enough to make you want to shove the old man into the lava.",0);
		add_dialog_str(1,"Push him into the lava?",0);
		add_dialog_choice(0,"Actually, I think there's just enough room to squeeze by...");
		add_dialog_choice(1,"Hope he likes barbeque!");
		choice = run_dialog(1);

		if(choice == 2){
			text_bubble_on_char(11,"");
			text_bubble_on_char(0,"MOVE IT PUNK!");
			force_view_center(char_loc_x(0),char_loc_y(0));
			force_instant_terrain_redraw();
			pause(20);

			text_bubble_on_char(0,"");
			text_bubble_on_char(0,"*shove*");
			text_bubble_on_char(11,"AIEEEE!");
			relocate_character(11,char_loc_x(11),(char_loc_y(11) - 1));
			force_instant_terrain_redraw();
			pause(4);

			text_bubble_on_char(11,"");
			text_bubble_on_char(0,"");
			force_instant_terrain_redraw();
			put_boom_on_char(11,0,0);
			run_animation_sound(-169);
			set_flag(2,2,2);
			set_flag(10,20,0);
			inc_flag(10,10,1);
			erase_char(11);
			}
			else{
				message_dialog("With a clear path to the exit, Nelson bounds forward and leaves, shouting 'hallelueahs' along the way.","");
				set_flag(2,2,2);
				set_flag(10,20,0);
				erase_char(11);
				}
		}
break;

beginstate EXIT_STATE;
break;

beginstate 10;
	if(get_flag(2,1) <= 0){
		block_entry(1);
		activate_hidden_group(1);
		put_boom_on_space(15,21,2,0);
		run_animation_sound(-10);
		force_view_center(15,21);
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(17,"ADVENTURERS!");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(17,"");
		text_bubble_on_char(17,"YOU ARE HERE TO UNCOVER OUR SECRET?");
		force_instant_terrain_redraw();
		pause(30);

		text_bubble_on_char(17,"");
		text_bubble_on_char(17,"I HOPE YOU DON'T CROSS THE LAVA MAZE...");
		force_instant_terrain_redraw();
		pause(35);

		text_bubble_on_char(17,"");
		text_bubble_on_char(17,"...AND DISCOVER IT!");
		force_instant_terrain_redraw();
		pause(20);

		text_bubble_on_char(17,"");
		force_instant_terrain_redraw();

		activate_hidden_group(4);
		put_boom_on_space(12,25,5,0);
		put_boom_on_space(18,25,5,0);
		put_boom_on_space(13,19,5,0);
		put_jagged_zap(15,21,12,25,4);
		put_jagged_zap(15,21,18,25,4);
		put_jagged_zap(15,21,13,19,4);
		run_animation_sound(43);

		text_bubble_on_char(17,"KEKEKEKEKEKEKEKEKE!");
		force_instant_terrain_redraw();
		pause(20);

		text_bubble_on_char(17,"");
		force_instant_terrain_redraw();

		put_boom_on_space(15,21,2,0);
		run_animation_sound(-10);
		erase_char(17);
		force_instant_terrain_redraw();
		pause(15);

		force_view_center(char_loc_x(0),char_loc_y(0));
		force_instant_terrain_redraw();

		set_flag(2,1,1);
		}
break;

beginstate 11;
	if(get_flag(2,2) <= 0){
		block_entry(1);
		force_view_center(15,15);
		flip_terrain(15,15);
		force_instant_terrain_redraw();

		play_sound(58);

		activate_hidden_group(10);
		force_view_center(15,16);
		force_instant_terrain_redraw();
		pause(10);

		flip_terrain(15,15);
		play_sound(-59);

		text_bubble_on_char(11,"AT LAST!");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(11,"");
		text_bubble_on_char(11,"I AM FREE OF THAT ACURSED PRISON!");
		force_instant_terrain_redraw();
		pause(30);

		text_bubble_on_char(11,"");
		text_bubble_on_char(11,"FREEDOM!");
		relocate_character(11,15,17);
		force_view_center(15,17);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,15,18);
		force_view_center(15,18);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,16,19);
		force_view_center(16,19);
		set_character_facing(11,6);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,17,19);
		force_view_center(17,19);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,18,19);
		force_view_center(18,19);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,19,20);
		force_view_center(19,20);
		set_character_facing(11,4);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,20,21);
		force_view_center(20,21);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,20,22);
		force_view_center(20,22);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,19,23);
		force_view_center(19,23);
		set_character_facing(11,2);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,18,23);
		force_view_center(18,23);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,17,22);
		force_view_center(17,22);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(11,16,21);
		force_view_center(16,21);
		play_sound(-47);
		force_instant_terrain_redraw();
		pause(10);

		text_bubble_on_char(11,"");
		text_bubble_on_char(11,"...");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(11,"");
		text_bubble_on_char(11,"Er...");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(11,"");
		text_bubble_on_char(11,"Could I get by?");
		force_instant_terrain_redraw();
		pause(30);

		text_bubble_on_char(11,"");
		force_view_center(15,21);
		force_instant_terrain_redraw();

		message_dialog("What a pain!  This insolent whelp is blocking your path!  Unfortunately, there doesn't appear to be any way to go around him.","");
		set_flag(2,2,1);
		}
break;
beginstate 12;
	if(get_flag(2,3) <= 0){
		kill_char(8,2,0);
		kill_char(9,2,0);
		kill_char(10,2,0);

		block_entry(1);
		activate_hidden_group(2);
		put_boom_on_space(16,13,2,0);
		run_animation_sound(-10);
		force_view_center(16,13);
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(18,"OH NO!");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(18,"");
		text_bubble_on_char(18,"YOU MADE IT THROUGH THE LAVA MAZE!");
		force_instant_terrain_redraw();
		pause(30);

		text_bubble_on_char(18,"");
		text_bubble_on_char(18,"NO...");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(18,"");
		text_bubble_on_char(18,"YOU MUST NEVER GO THROUGH THE DOOR...");
		force_instant_terrain_redraw();
		pause(40);

		text_bubble_on_char(18,"");
		text_bubble_on_char(18,"...THAT DOOR BY THE END OF THE HALL...");
		force_instant_terrain_redraw();
		pause(40);

		text_bubble_on_char(18,"");
		text_bubble_on_char(18,"...AND DISCOVER OUR SECRET!");
		force_instant_terrain_redraw();
		pause(25);

		text_bubble_on_char(18,"");
		text_bubble_on_char(18,"KEKEKEKEKEKEKEKEKE!");
		force_instant_terrain_redraw();
		pause(20);

		put_boom_on_space(16,13,2,0);
		run_animation_sound(-10);
		erase_char(18);
		force_instant_terrain_redraw();
		pause(15);

		force_view_center(char_loc_x(0),char_loc_y(0));
		force_instant_terrain_redraw();

		set_flag(2,3,1);
		}
break;
beginstate 13;
	if(get_flag(2,4) <= 0){
		message_dialog("Suddenly, a voice enters your head.  It is the voice of that weird bat creature.","_ADVENTURERS, DO NOT PROCEED FOR THIS WHEEL DOES NOT OPEN THE GATE THAT LEADS TO OUR SECRET!  THIS IS UNIMPORTANT THOUGH, AS THIS WALL OF OGRES IS IMMPENETRABLE!  YOU MUST NOT TRY TO FIND WHICH ONE IS TICKLISH FOR IT IS IMPOSSIBLE!  KEKEKEKEKEKE!_");
		set_flag(2,4,1);
		}
break;
beginstate 14;
	if(get_flag(2,5) <= 0){
		reset_dialog_preset_options(8);
		choice = run_dialog(0);
			if(choice == 2){
				flip_terrain(12,13);
				flip_terrain(12,14);
				play_sound(99);
				set_flag(2,5,1);
				}
				else{
					end();
					}
		}
break;
beginstate 15;
	if(get_flag(2,6) <= 0){
		message_dialog("As you descend the steps, the bat creature's voice enters your head once again.","_I SEE YOU ARE AS CLEVER AS YOU ARE STUPID!  LET'S SEE IF YOU'RE STUPID ENOUGH TO FIND THE KEY AT THE END OF THIS TUNNEL!_");
		set_flag(2,6,1);
		}
break;
beginstate 16;
	if(get_flag(2,7) <= 0){
		message_dialog("Inside the chest, you find nothing but a small key.  You pocket it and move on.","");
		change_spec_item(1,1);
		set_flag(2,7,1);
		}
break;
beginstate 17;
	if(get_flag(2,8) <= 0){
		block_entry(1);
		activate_hidden_group(3);
		put_boom_on_space(25,14,2,0);
		run_animation_sound(-10);
		force_view_center(25,14);
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(6,"");
		text_bubble_on_char(6,"THIS IS YOUR LAST CHANCE TO TURN BACK!");
		force_instant_terrain_redraw();
		pause(30);

		text_bubble_on_char(6,"");
		text_bubble_on_char(6,"GIVE UP, FOR THESE LEVERS DO NOTHING!");
		force_instant_terrain_redraw();
		pause(30);

		text_bubble_on_char(6,"");
		text_bubble_on_char(6,"YES, THESE LEVERS HAVE NOTHING TO DO...");
		force_instant_terrain_redraw();
		pause(25);

		text_bubble_on_char(6,"");
		text_bubble_on_char(6,"WITH THE GATE LEADING TO MY CHAMBER...");
		force_instant_terrain_redraw();
		pause(25);

		text_bubble_on_char(6,"");
		text_bubble_on_char(6,"OVER THERE, AT THE END OF THIS ROOM...");
		force_instant_terrain_redraw();
		pause(25);

		text_bubble_on_char(6,"");
		text_bubble_on_char(6,"...OR WITH OUR PRECIOUS SECRET!");
		force_instant_terrain_redraw();
		pause(25);

		text_bubble_on_char(6,"");
		text_bubble_on_char(6,"KEKEKEKEKEKEKEKEKE!");
		force_instant_terrain_redraw();
		pause(20);

		put_boom_on_space(25,14,2,0);
		run_animation_sound(-10);
		erase_char(6);
		force_instant_terrain_redraw();
		pause(15);

		force_view_center(char_loc_x(0),char_loc_y(0));
		force_instant_terrain_redraw();

		set_flag(2,8,1);
		}
break;

beginstate 18;
	if(get_flag(2,9) <= 0){
		block_entry(1);
		activate_hidden_group(5);
		set_total_visibility(1);
		put_boom_on_space(24,20,2,0);
		run_animation_sound(-10);
		force_view_center(24,20);
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(16,"YOU ARE TOO CURIOUS FOR YOUR OWN GOOD!");
		force_instant_terrain_redraw();
		pause(30);

		text_bubble_on_char(16,"");
		text_bubble_on_char(16,"NO, I'LL NEVER TELL YOU THE SECRET...");
		force_instant_terrain_redraw();
		pause(30);

		text_bubble_on_char(16,"");
		text_bubble_on_char(16,"EVEN IF YOU PUNISH ME...");
		force_instant_terrain_redraw();
		pause(25);

		text_bubble_on_char(16,"");
		text_bubble_on_char(16,"PUNISH ME AS MUCH AS YOU WANT!");
		force_instant_terrain_redraw();
		pause(25);

		text_bubble_on_char(16,"");
		put_boom_on_space(24,20,2,0);
		run_animation_sound(-10);
		relocate_character(16,9,3);
		force_instant_terrain_redraw();
		pause(15);

		put_boom_on_space(25,23,2,0);
		run_animation_sound(-10);
		relocate_character(16,25,23);
		force_view_center(25,23);
		force_instant_terrain_redraw();
		pause(15);

		set_character_facing(16,2);
		force_instant_terrain_redraw();
		pause(10);

		set_character_pose(16,1);
		play_sound(-34);
		force_instant_terrain_redraw();
		pause(10);

		set_character_pose(16,0);
		set_character_facing(16,0);
		force_instant_terrain_redraw();

		put_effect_on_space(24,23,10,3,1);
		put_sparkles_on_space(24,23,1,6);
		run_animation_sound(-163);
		pause(15);

		text_bubble_on_char(16,"KEKEKEKEKEKEKEKEKE!");
		force_instant_terrain_redraw();
		pause(20);

		text_bubble_on_char(16,"");
		force_view_center(char_loc_x(0),char_loc_y(0));
		set_total_visibility(0);
		force_instant_terrain_redraw();

		set_flag(2,9,1);
		set_flag(2,20,1);
		}
break;
beginstate 19;
	if(get_flag(2,7) == 1){
		play_sound(-33);
		text_bubble_on_char(0,"!");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(0,"");
		force_instant_terrain_redraw();
		play_sound(-33);
		pause(5);

		play_sound(152);

		play_sound(-33);
		pause(3);

		play_sound(-152);
		pause(6);

		play_sound(33);

		set_terrain(11,3,137);
		set_terrain(11,4,137);
		play_sound(108);

		text_bubble_on_char(0,"?");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(0,"");
		relocate_character(7,10,4);
		set_character_facing(7,6);
		set_character_pose(7,0);
		play_sound(-49);
		force_instant_terrain_redraw();
		pause(10);

		relocate_character(7,11,4);
		play_sound(-50);
		force_instant_terrain_redraw();
		pause(10);

		relocate_character(7,12,4);
		play_sound(-49);
		force_instant_terrain_redraw();
		pause(10);

		text_bubble_on_char(0,".");
		force_instant_terrain_redraw();
		pause(10);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"..");
		force_instant_terrain_redraw();
		pause(10);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"...");
		force_instant_terrain_redraw();
		pause(20);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"!");
		set_character_pose(7,1);
		force_instant_terrain_redraw();
		play_sound(-33);
		pause(15);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"H");
		set_character_pose(7,0);
		force_instant_terrain_redraw();
		pause(1);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"HO");
		force_instant_terrain_redraw();
		pause(1);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"HOL");
		force_instant_terrain_redraw();
		pause(1);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"HOLY");
		force_instant_terrain_redraw();
		pause(1);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"HOLY H");
		force_instant_terrain_redraw();
		pause(1);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"HOLY HE");
		force_instant_terrain_redraw();
		pause(1);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"HOLY HEL");
		force_instant_terrain_redraw();
		pause(1);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"HOLY HELL");
		force_instant_terrain_redraw();
		pause(1);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"HOLY HELL!");
		force_instant_terrain_redraw();
		pause(20);

		text_bubble_on_char(0,"");
		text_bubble_on_char(0,"IT'S A BEAR!");
		force_instant_terrain_redraw();
		pause(20);

		text_bubble_on_char(0,"");
		force_instant_terrain_redraw();

		message_dialog("OH NO IT'S A BEAR!!!  RUN FOR YOUR LIVES!!!","");
		set_flag(2,7,2);
		}
break;

beginstate 20; //prevent from not crossing lava
	if(get_flag(2,2) <= 0){
		print_str_color("Bad idea!  There's no reason to hurt yourself!",3);
		block_entry(1);
		}
break;

beginstate 21; // security control
	if(get_flag(5,0) == off){
		reset_dialog();
		add_dialog_str(0,"You spot a lever connected to a long series of wires.  A plate on it reads 'Security Control.'  The lever has two settings: 'Rock' and 'Gate.' The lever is currently in the 'Rock' position.",0);
		add_dialog_str(1,"Pull the lever?",0);
		add_dialog_choice(0,"No");
		add_dialog_choice(1,"Yes");
		choice = run_dialog(0);

		if(choice == 2){
			print_str_color("The lever is now set to 'Gate.'",3);
			play_sound(34);
			flip_terrain(23,9);
			set_flag(5,0,1);
			set_flag(5,1,1);
			if(get_flag(5,2) <= 0){
				play_sound(-57);
				message_dialog("Suddenly, the wall next to you sinks into the floor!","");
				set_terrain(24,9,0);
				set_terrain(24,10,0);
				set_terrain(24,11,0);
				set_terrain(25,11,0);
				force_instant_terrain_redraw();
				set_flag(5,2,1);
				}
			end();
			}
			else{
				end();
				}
		}
	if(get_flag(5,0) == on){
		reset_dialog();
		add_dialog_str(0,"You spot a lever connected to a long series of wires.  A plate on it reads 'Security Control.'  The lever has two settings: 'Rock' and 'Gate.' The lever is currently in the 'Gate' position.",0);
		add_dialog_str(1,"Pull the lever?",0);
		add_dialog_choice(0,"No");
		add_dialog_choice(1,"Yes");
		choice = run_dialog(0);

		if(choice == 2){
			print_str_color("The lever is now set to 'Rock.'",3);
			play_sound(34);
			flip_terrain(23,9);
			set_flag(5,0,0);
			set_flag(5,1,0);
			end();
			}
			else{
				end();
				}
		}
break;

beginstate 22; // gate control
	if(get_flag(5,1) == off){
		reset_dialog();
		add_dialog_str(0,"You spot a lever connected to a long series of wires running through the ground.  A plate on it reads 'Gate Control.'",0);
		add_dialog_str(1,"Pull the lever?",0);
		add_dialog_choice(0,"No");
		add_dialog_choice(1,"Yes");
		choice = run_dialog(0);

		if(choice == 2){
			if(run_select_a_pc(0) == 1){
				play_sound(-108);
				message_dialog("Uh oh!  A rock falls from the ceiling on top of you!","");
				kill_char(get_selected_pc(),3,0);
				set_terrain(char_loc_x(get_selected_pc()),char_loc_y(get_selected_pc()),137);
				append_char_name(get_selected_pc());
				append_string(" is ");
				append_string("flattened!");
				get_buffer_text(teststring);
				print_str_color(teststring,3);
				}
				else{
					end();
					}
			}
			else{
				end();
				}
		}

	if(get_flag(5,1) == on){
		reset_dialog();
		add_dialog_str(0,"You spot a lever connected to a long series of wires running through the ground.  A plate on it reads 'Gate Control.'",0);
		add_dialog_str(1,"Pull the lever?",0);
		add_dialog_choice(0,"No");
		add_dialog_choice(1,"Yes");
		choice = run_dialog(0);

		if(choice == 2){
			play_sound(99);
			flip_terrain(24,18);
			}
			else{
				end();
				}
		}
break;

beginstate 23; // magic control
	reset_dialog();
	add_dialog_str(0,"You spot a lever that doesn't seem to be connected to anything.  A plate on it reads 'Magic Lever.'  The lever has two settings: 'Magic' and 'More Magic.' The lever is currently in the 'More Magic' position.",0);
	add_dialog_str(1,"Pull the lever?",0);
	add_dialog_choice(0,"No");
	add_dialog_choice(1,"Yes");
	choice = run_dialog(0);

	if(choice == 2)
		kill_char(1000,3,0);
		else{
			end();
			}
break;
beginstate 24;//portal door
	if(get_flag(2,25) == 1){
		message_dialog("You check the wall where the note said not to look.  Lo and behold, you find a carefully hidden secret door.","");
		set_terrain(27,26,20);
		set_flag(2,25,2);
		}
break;
beginstate 25;//portal
	reset_dialog_preset_options(3);
	choice = run_dialog(0);

	if(choice == 2){
		revive_party();
		play_sound(10);
		move_to_new_town(1,26,16);
		}
		else{
			block_entry(1);
			end();
			}
		}
break;

beginstate 30; // can't leave yet
	if(get_flag(2,1) >= 1){
		message_dialog("You try to leave the cave but your bad dude attitude keeps you from whimping out.","");
		block_entry(1);
		}
break;